﻿namespace test3

open System
open System.Management

open wmi
open util

module vmms =

    ////////////////////////
    // VMMS
    ////////////////////////
    let msvm = new WmiEnum("msvm_")
    let cim = new WmiEnum("cim_")

    type Vmms() =
        member private x.vmms = msvm?VirtualSystemManagementService |> Seq.head
        member this.definevm (setting:string) =
            let args:obj array = [| setting; null; null; 0; 0 |]
            let ret:uint32 = this.vmms.invoke?DefineVirtualSystem args
            let vmpath:string = unbox args.[3]
            let jobpath:string = unbox args.[4]
            printfn "%A %A" vmpath jobpath
            wait_for jobpath
            check_ret ret
            vmpath
        member this.modifyres (vmpath:string) (res:string array) =
            let args:obj array = [| vmpath; res; 0 |]
            let ret:uint32 = this.vmms.invoke?ModifyVirtualSystemResources args
            let jobpath:string= unbox args.[2]
            printfn "%A" jobpath
            wait_for jobpath
            check_ret ret
            ()
        member this.destoryvm (vmpath:string) =
            let args:obj array = [| vmpath; 0 |]
            let ret:uint32 = this.vmms.invoke?DestroyVirtualSystem args
            let jobpath:string  = unbox args.[1]
            wait_for jobpath
            check_ret ret
            ()
        member this.addres (vmpath:string) (res:string array) =
            let args:obj array = [| vmpath; res; 0; 0 |]
            let ret:uint32 = this.vmms.invoke?AddVirtualSystemResources args
            let jobpath:string = unbox args.[3]
            wait_for jobpath
            check_ret ret
            ()

    let vmms = new Vmms()